#if !defined(_HELP_)
#define _HELP_

#include <math.h>

int factI(int n){
    int r = 1;
    while(n > 0) r *= n--;
    return r;
}


void normalize(int *in, int size, int *out){
    int i, j;
    for(i = size-1; i >= 0; i--){
        out[i] = in[size - 1 - i];
        for(j = 0; j < size; j++)
            if(out[j] >= in[size - 1 - i]) out[j]++;
        out[i]--;
    }
}


void decode(int num, int size, int *out){
    int i;

    for(i = 0; i < size; i++) out[i] = 0;

    size -= 2;

    for(i = size + 1;; i--) {
        if( num == 0) {
            out[i] = 0;
            break;
        } else {
            int f = factI(i);
            out[i] = num / f;
            size--;
            num = num % f;
        }
    }

}

#endif	/* _HELP_ */